﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MugenInjection;
using MugenInjection.Interface;

namespace MugenInjectionTest.Core
{
    public partial class InjectorResolverTest
    {
        [TestMethod]
        public void TestGetAllGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                injector.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters);
                var all = injector.GetAll<string>(parameters);
                Assert.AreEqual(all.Count(), 2);
                Assert.AreEqual(all.ElementAt(0), string.Empty);
                Assert.AreEqual(all.ElementAt(1), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict);
                var all = injector.GetAll<string>(dict);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters);
                var all = injector.GetAll<string>(dict, parameters);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .NamedBinding(name);
                var all = injector.GetAll<string>(name);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict)
                    .NamedBinding(name);
                var all = injector.GetAll<string>(name, dict);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters)
                    .NamedBinding(name);
                var all = injector.GetAll<string>(name, dict, parameters);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestGetAllIntoGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var typeInto = typeof(Attribute);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto<string>(TypeInto, ParameterInfo, null, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto<string>(TypeInto, ParameterInfo, dict);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto<string>(TypeInto, ParameterInfo, dict, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto<string>(name, TypeInto, ParameterInfo);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto<string>(name, TypeInto, ParameterInfo, dict);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto<string>(name, TypeInto, ParameterInfo, dict, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestGetAllNonGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var bindType = typeof(string);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                injector.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters);
                var all = injector.GetAll(bindType, parameters);
                Assert.AreEqual(all.Count(), 2);
                Assert.AreEqual(all.ElementAt(0), string.Empty);
                Assert.AreEqual(all.ElementAt(1), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict);
                var all = injector.GetAll(bindType, dict);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters);
                var all = injector.GetAll(bindType, dict, parameters);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .NamedBinding(name);
                var all = injector.GetAll(bindType, name);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict)
                    .NamedBinding(name);
                var all = injector.GetAll(bindType, name, dict);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters)
                    .NamedBinding(name);
                var all = injector.GetAll(bindType, name, dict, parameters);
                Assert.AreEqual(all.Count(), 1);
                Assert.AreEqual(all.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestGetAllIntoNonGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var typeInto = typeof(Attribute);
            var bindType = typeof(string);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto(bindType, TypeInto, ParameterInfo, null, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto(bindType, TypeInto, ParameterInfo, dict);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                var allInto = injector.GetAllInto(bindType, TypeInto, ParameterInfo, dict, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto(bindType, name, TypeInto, ParameterInfo);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto(bindType, name, TypeInto, ParameterInfo, dict);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                var allInto = injector.GetAllInto(bindType, name, TypeInto, ParameterInfo, dict, parameters);
                Assert.AreEqual(allInto.Count(), 1);
                Assert.AreEqual(allInto.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestTryGetAllGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                injector.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters);
                Assert.IsTrue(injector.TryGetAll(out result, parameters));
                Assert.AreEqual(result.Count(), 2);
                Assert.AreEqual(result.ElementAt(0), string.Empty);
                Assert.AreEqual(result.ElementAt(1), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict);
                Assert.IsTrue(injector.TryGetAll(out result, dict));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters);
                Assert.IsTrue(injector.TryGetAll(out result, dict, parameters));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(out result, name));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(out result, name, dict));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(out result, name, dict, parameters));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestTryGetAllNonGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var bindType = typeof(string);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                injector.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, parameters));
                Assert.AreEqual(result.Count(), 2);
                Assert.AreEqual(result.ElementAt(0), string.Empty);
                Assert.AreEqual(result.ElementAt(1), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, dict));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, dict, parameters));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, name));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, name, dict));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> result;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(TypeInto.AsType());
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters)
                    .NamedBinding(name);
                Assert.IsTrue(injector.TryGetAll(bindType, out result, name, dict, parameters));
                Assert.AreEqual(result.Count(), 1);
                Assert.AreEqual(result.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestTryGetAllIntoGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var typeInto = typeof(Attribute);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                injector.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters && context.TypeInto == TypeInto.AsType() &&
                                     context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, TypeInto, ParameterInfo, null, parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, TypeInto, ParameterInfo, dict));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, TypeInto, ParameterInfo, dict, parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, name, TypeInto, ParameterInfo));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, name, TypeInto, ParameterInfo, dict));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<string> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(out allInCurrentInto, name, TypeInto, ParameterInfo, dict,
                                                              parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
        }

        [TestMethod]
        public void TestTryGetAllIntoNonGeneric()
        {
            var parameters = new IInjectionParameter[1];
            var dict = new Dictionary<string, object>();
            const string name = "test";
            const string value = "value";
            var typeInto = typeof(Attribute);
            var bindType = typeof(string);

            //Only parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                injector.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.Parameters == parameters && context.TypeInto == TypeInto.AsType() &&
                                     context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, TypeInto, ParameterInfo, null, parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only special parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>().ToConstant(value).When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, TypeInto, ParameterInfo, dict));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only special parameters and parameters
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, TypeInto, ParameterInfo, dict, parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, name, TypeInto, ParameterInfo));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding and special parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, name, TypeInto, ParameterInfo, dict));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
            //Only named binding and special parameters and parameters.
            using (MugenInjector parent = GetInjector())
            {
                var injector = (MugenInjector)parent.CreateChild();
                IEnumerable<object> allInCurrentInto;
                parent.Bind<string>().ToConstant(string.Empty).WhenInto(typeInto);
                parent.Bind<string>()
                    .ToConstant(value)
                    .When(context => context.SpecialParameters == dict && context.Parameters == parameters && context.TypeInto == TypeInto.AsType() && context.ParameterInfo == ParameterInfo)
                    .NamedBinding(name);

                Assert.IsTrue(injector.TryGetAllInto(bindType, out allInCurrentInto, name, TypeInto, ParameterInfo, dict,
                                                              parameters));
                Assert.AreEqual(allInCurrentInto.Count(), 1);
                Assert.AreEqual(allInCurrentInto.ElementAt(0), value);
            }
        }
    }
}
